import http2 = require('http2');
import fs = require('fs');
import path = require('path');
import express = require('express');
import config from '../../config';
import bodyParser = require('body-parser');
import webHook from './router/webhook';

class StaticServer {
  //server: http2.Http2SecureServer;
  app: express.Application;
  constructor() {
    this.app = express();
    this.app.use(bodyParser.json());
    this.app.use(bodyParser.urlencoded({ extended: false }));
    this.app.use(config.baseUrl, webHook);
    // this.server = http2.createSecureServer({
    //   key: fs.readFileSync(path.resolve(config.keyPath, './5045558_syk2018.cn.key')),
    //   cert: fs.readFileSync(path.resolve(config.keyPath, './5045558_syk2018.cn.pem')),
    // });
  }

  start(): void {
    //this.server.listen(config.port);
    this.app.listen(config.port, () => {
      console.log(`Server is listening on ${config.port}`);
    });
  }

  getServer(): Express.Application {
    return this.app;
  }
}

export default new StaticServer();
